<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>
        给一段文章中的全部指定词语进行过滤<br>
        // 比如我要过滤 "SM"<br>

        var str = 'asdasdSMasdasdasdSMsdasdasdSMsadasd'<br>

        // 需要结果<br>
        // asdasd**asdasdasd**sdasdasd**<br>
    </div>
    <script>
        
        function filtration( str , a , b ) {
            var arr = str.split("");
            for( var i = 0 ; i < arr.length ; i ++ ) {
                if ( i == arr.length - 1 ) {
                    return arr.join("") ; 
                } else {
                    if( arr[i] == a ) {
                        if( arr[i+1] == b ){
                            arr[i] = "*" ; 
                            arr[i+1] = "*" ;
                        }
                    }
                }
            }
            return arr.join("") ;
        }
        var str = 'asdasdSMasdasdasdSMsdasdasdSMsadasd';
        console.log(filtration(str,"S","M"));
    </script>
</body>
</html>